package paralla

import (
	"context"
	"errors"
	"log"
	"runtime"
)

func PanicRecoverDecorator(f func() error, ctx context.Context) (err error) {
	defer func() {
		if ex := recover(); ex != nil {
			LogEndReportPanic(ctx, ex)
			err = errors.New("go routine has panic")
		}
	}()
	return f()
}
func LogEndReportPanic(ctx context.Context, err interface{}) {
	buf := make([]byte, 1<<16)
	stackSize := runtime.Stack(buf, false)
	log.Println(string(buf[0:stackSize]))
}
